﻿Namespace Seguranca.Dominio

    <Serializable()> _
    Public Class PapelUsuario

        Private _id As Nullable(Of Long)
        Public Overridable Property Id() As Nullable(Of Long)
            Get
                Return _id
            End Get
            Set(ByVal value As Nullable(Of Long))
                _id = value
            End Set
        End Property

        Private _papel As Papel
        Public Overridable Property Papel() As Papel
            Get
                Return _papel
            End Get
            Set(ByVal value As Papel)
                _papel = value
            End Set
        End Property

        Private _usuario As Usuario
        Public Overridable Property Usuario() As Usuario
            Get
                Return _usuario
            End Get
            Set(ByVal value As Usuario)
                _usuario = value
            End Set
        End Property

        Public Overrides Function Equals(ByVal obj As Object) As Boolean

            If IsNothing(obj) Then
                Return False
            End If

            Dim _objeto = TryCast(obj, PapelUsuario)
            If IsNothing(_objeto) Then
                Return False
            End If

            If Me.Papel.Id = _objeto.Papel.Id And Me.Usuario.Id = _objeto.Usuario.Id Then
                Return True
            End If

            Return False

        End Function

        Public Overrides Function GetHashCode() As Integer

            Return (Me.Papel.Id + "|" + Me.Usuario.Id).GetHashCode()

        End Function

    End Class

End Namespace